package com.baidu.service.impl;

import com.baidu.utils.ResultResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.pojo.TbCategory;
import com.baidu.service.TbCategoryService;
import com.baidu.mapper.TbCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbCategoryServiceImpl extends ServiceImpl<TbCategoryMapper, TbCategory>
    implements TbCategoryService{

    @Autowired
    private TbCategoryMapper tbCategoryMapper;

    @Override
    public ResultResponse findCategorys(Long parentId) {
        if(parentId == null){
            parentId = 0L;
        }
        List<TbCategory> list = tbCategoryMapper.findCategorys(parentId);
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse saveAndUpdate(TbCategory tbCategory) {
        if(tbCategory.getId() == null){
            this.tbCategoryMapper.insert(tbCategory);
        }else{
            this.tbCategoryMapper.updateById(tbCategory);
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse findById(Long id) {
        TbCategory tbCategory = this.tbCategoryMapper.selectById(id);
        return ResultResponse.SUCCESS(tbCategory);
    }

    @Override
    public ResultResponse deleteIds(Long[] ids) {
        for (Long id : ids) {
            this.tbCategoryMapper.deleteById(id);
        }
        return ResultResponse.SUCCESS();
    }
}




